package org.xs.web.http.provider.servlet;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

import org.xs.web.http.provider.HTTPCookie;
import org.xs.web.http.provider.HTTPHeader;
import org.xs.web.http.provider.HTTPResponse;

public class HTTPServletResponse implements HTTPResponse {
	private HttpServletResponse delegate;
	
	public HTTPServletResponse(HttpServletResponse response){
		 delegate = response;
	}
	
	public HttpServletResponse getDelegate(){
		return delegate;
	}

	@Override
	public void addHeader(String name, String value) {
		delegate.addHeader(name, value);
	}

	@Override
	public void addHeader(HTTPHeader[] headers) {
		for(HTTPHeader header: headers){
			addHeader(header.name(), header.value());
		}
	}

	@Override
	public void addHeader(HTTPHeader header) {
		addHeader(header.name(),header.value());
	}

	@Override
	public void setStatus(int code) {
		delegate.setStatus(code);
	}

	@Override
	public void addCookie(HTTPCookie cookie) {
		Cookie c = new Cookie(cookie.name, cookie.value);
		c.setDomain(cookie.domain);
		c.setPath(cookie.path);
		c.setMaxAge(cookie.maxArg);
		c.setVersion(cookie.version);
		c.setSecure(cookie.secure);
		delegate.addCookie(c);
	}

	@Override
	public void addCookie(HTTPCookie[] cookies) {
		for(HTTPCookie cookie : cookies){
			addCookie(cookie);
		}
	}
	
}
